Skip to content

fix(studio): a sealed undo of a GSAP-animated layer's style shows in place - #8320

Merged
miguel-heygen merged 74 commits into
mainfrom
fix/sealed-undo-gsap-in-place
Nov 22, 2026
Merged

miguel-heygen merged 74 commits into
mainfrom
fix/sealed-undo-gsap-in-place

Conversation

@miguel-heygen

@miguel-heygen miguel-heygen commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

What

In a sealed preview (Studio cannot script the frame), undoing or redoing a change to the style of a layer GSAP animates now shows in place. Before, it reloaded the whole preview. A crop is the common case: undoing a crop of a tweened or gsap.set layer blanked and rebuilt the preview, and the layer showed the crop until the reload finished. An unsealed preview already restored it in place.

The sealed preview is off by default until the sealed-by-default change (#7846) lands, so nothing changes for anyone before then.

Why

A crop saves only the layer's style; the GSAP script does not change. So a sealed undo sends restore-attributes. The frame refuses it for any element GSAP has parsed when the page has a script: by its own rule, such an element needs a re-run instead. Studio never sent the re-run; it reloaded the preview. A same-origin preview re-runs the script in place for the same undo.

How

The re-run travels in the same restore-attributes request, and the frame decides, since only the frame knows which elements GSAP has parsed. Nothing is sent after the reply, so no later edit, undo, scrub or new preview load can be overwritten by it. The frame runs the re-run synchronously in its request's turn, in the order requests arrive; the one exception is a script that first loads the MotionPath plugin, which finishes later. That wait is one state machine in softReloadFrame, for every soft reload in both modes:

  • A run writes the file's own state (its restore plan and timing) when it starts, in the order requests arrive, as before. Only the timeline swap waits: kill its own timelines, reset their tweened styles, remove its own stale script, run the script, finish.
  • Each timeline a run replaces is numbered when the run starts. When the plugin arrives, a waiting run swaps only if no newer run replaced any of its timelines; otherwise it changes nothing and answers superseded, which Studio treats as done (no reload). A plugin failure is answered the same way: cannot-soft-reload (Studio reloads) only for a run still current.
  • While a run waits, nothing of its own is touched, so the old timelines keep playing over the restored attributes, exactly as before this change.
  • A swap that waited finishes at the player's live time, read just before it, so a scrub, playback or another run's swap during the wait is kept. A run that never waits finishes at the time Studio sent.
  • While a swap waits on a timeline, the frame refuses an in-place edit of it (patch-tweens answers patched: false, live-retime answers unchanged, Studio's same-origin patch returns false), so Studio re-runs the saved script and the newest script supersedes the waiting run. The drag-time gsap-set preview is left alone; its commit goes through those refused paths.
  • Studio keeps one record per sealed preview load (utils/sealedPreviewLedger.ts): every write it sends takes a ticket with its timelines, its send order and the file version its save produced. A late answer (a refusal, a timeout, a failure, a refused patch's fallback) is dropped only when a later re-run of all its timelines, read at that file version or newer, was sent; that re-run carries the change and owns its own recovery. Tween patches and retimes never cover anything. An uncovered change recovers with the newest saved script for its timelines, never the script its request captured. An answer from a replaced preview load does nothing.
  • A restore covers its timelines only when the frame says it re-ran the script (restore-attributes now answers reran), counted from the restore's send order.
  • Coverage rule: a late failure of a write is dropped only when a newer re-run of all its timelines was sent, read at the same saved file version or later, and carrying everything the write changed: restored attributes are never covered, and clip timing only by a re-run that carried timing too (every recovery re-run does). Coverage counts from the newer run's send, because that run owns its own recovery to the newest saved file, which holds the older change. Waiting for the newer run's success instead would add needless reloads: an older refusal arriving while the newer run's success is still in transit, and an older script-only run timing out with a newer run sent, both reload under that rule.
  • A write that carries restored attributes or clip timing waits SAVED_STATE_DEADLINE_MS (30 s, in sealedPreviewLedger.ts) for the frame's answer, not the port's usual 5 s; still unanswered then, it recovers with a full reload. A late success inside that window resolves cleanly. Before this round, a script-only re-run could cover such a write once it timed out at 5 s, so its refusal after the deadline was dropped and the old title or data-start stayed.
  • Every sealed write (soft re-run, live retime, tween patch, restore) goes out through one ledger send, sendPreviewWrite. Once the frame can take it, a write whose saved file version is older than one already sent to that preview load is not sent: an older timing sync whose sync goes out after a newer save's would otherwise put its file's clip timing over the newer file's. It recovers the way that sender's refusal does: nothing when an already-sent re-run of a newer file carried its change, else a re-run of the newest saved file in place, else a full reload (a newer undo of attributes alone leaves no script snapshot to re-run). A re-run's coverage is recorded at that send, and only when it is sent, ranked by file version first.
  • A new preview load starts its send floor at the file revision Studio's shadow reload recorded when the load began and checked before showing it (useShadowPreviewReload.ts): it is handed to the ledger as the load is promoted, so the one record of which file a load shows sets the floor. A write older than that is not sent to the new load and recovers by a reload, so a timing completion held across a reload cannot put an older file's clip timing on the newer load. A save whose request went out before a reload began but finished after it is below that floor too: its sync reloads once more rather than being lost.
  • A write's file version is the Studio file revision its own save request went out at, carried with the save result (gsap mutations, the timing sync and undo), not the revision when its preview sync happens to run. The ledger keeps each timeline's newest snapshot by that version. GSAP commits send their preview sync inside the per-file lock (useGsapScriptCommits.ts:455), so their responses cannot reverse; the timing sync (timelineTimingSync.ts:353) and undo (useEditHistoryActions.ts:101) send theirs after the lock, so a newer save's sync can go out first, and before this the older one then looked newest.
  • A re-run that carried timing keeps its own coverage record per timeline: a later script-only re-run replaces only the script record, since it leaves the applied timing in place.
  • The ledger keeps the newest saved file version sent to each preview load, from every write, restores included. A recovery re-runs a snapshot in place only when it is that newest file; otherwise it reloads. A file with two GSAP scripts has no single script to snapshot, so an undo there records none, and an older patch's late refusal used to re-run the older file over it.
  • Earlier rule, superseded above: a request that carries saved state a script-only re-run never sends again (restored attributes, or clip timing) is never covered once the frame refuses it explicitly; it recovers with a full reload. A timeout stays coverable: the frame takes requests in order and writes that state when the run starts.
  • A saved snapshot is complete by type (script, both files, timing) and every recovery passes it on whole; a restore records one only when it re-runs its script.
  • Every recovery re-run carries the newest saved file's timing (newestPreviewWrite, which every late failure uses to pick what to re-run): an earlier save's timing may never have reached the frame, and the newest file holds it. The timing sent is the saved file's own values, so it changes nothing when they are already on screen.
  • A late live-retime recovery re-runs at Studio's playhead when the recovery runs, not when the retime was sent, so a scrub since then stays; every other recovery already read it then.
  • A sealed re-run or live retime keeps "the frame answered with an error" apart from "no reply" (previewAnswer in previewChannel.ts; previewRequest keeps answering null for both, for its other callers). Every error code except timeout and disposed counts as an explicit refusal, failed included: the frame may have applied part of the request before failing, which is safe only because a refusal of saved state is never covered and recovers with a full reload, the saved file.
  • One MotionPath loader in core serves everything: every waiting run queues on the single request in flight, and its load or error settles them all at once, in arrival order. A failed load is not remembered; the next run requests it again. Studio's same-origin preload now calls it too, instead of keeping its own copy. A sealed preview starts the load when Studio connects, from the same address owner (previewMotionPathUrl), so the first motion-path re-run after a load does not wait in either mode.

State: a sealed preview after late answers in any order; orderings tested: generated sequences of script re-runs, tween patches, retimes, restore-safe and unsafe attribute undos and script-plus-attribute undos, live retimes through Studio's moveLiveTweens, each reaching the frame, refused, or rejected by the port before the frame applies anything, replies answered in random orders, scrubs, frame reloads; oracle: equals a fresh load of the saved file, the playhead where Studio last put it, full reload only after a refusal nothing recovers in place. State: late answers from a sealed preview (soft re-run, tween patch, retime, restore); orderings tested: an older refusal after a newer re-run, a refused patch held while a newer patch lands, an older refusal after an unrelated successful patch, an older run timing out after an attribute-only undo, a re-run sent while a patch's write was in flight, a restore answered after the preview reloaded; in Studio unit tests and in real Chromium with the frame's replies held. State: the soft-reload wait; orderings tested: plugin ok or failing; before or after a scrub, playback, a newer run on the same timeline (also held past the editing port's deadline), a newer run on another timeline (also two waiting at once), an in-place tween patch, a drag preview, an attribute restore, and an edit to a property the timeline does or does not animate; in core, and in real Chrome sealed and unsealed; not tested: a live-retime during the wait in Chrome (its refusal is the same check as patch-tweens).

Core:

  • restore-attributes takes an optional rerun: the script, standalone sets, authored styles and timing a soft-reload takes. The request's own time and scopes complete it. A rerun the frame cannot take (an unknown or over-limit field, an empty script) is dropped and the restore kept: a restore that needs no re-run still applies in place, and one that needs it is refused, so Studio reloads.
  • When a restored element is one GSAP has parsed, the frame calls the existing softReload with them. It plans the attributes with the same planRestore, so every rule there applies, fix(core): a redo in a sealed preview puts Studio's edit marks back in place #8264's included. Otherwise it sets the attributes as before, and the script does not run.
  • A frame built before this change refuses the unknown field, so Studio reloads, as it does today.

Studio:

  • applySealedRestore attaches the rerun only when the file keeps a GSAP script. It builds it with sealedRerun, the builder soft-reload now uses as well. A refusal, or no reply while the run is still the newest, reloads the preview.
  • Parity fix: a sealed patch-tweens refusal, during a wait or not, used to reload the whole preview. It now re-runs the saved script in place, the path a same-origin preview takes when a patch misses (applyPreviewSync owns that one fallback for both). A full reload comes only when the re-run answers cannot-soft-reload.

The editing agent serves only a page marked for Studio, connected from its parent window (editingAgent.ts:285, :289). A render's page is its own top window, so no render reaches restore-attributes or the re-run.

Test plan

Core, softReload.test.ts, "restore-attributes with a re-run":

  • re-runs the script in the same request when GSAP has parsed a restored element (attributes set before the rebind, at the request's time);
  • refuses and changes nothing when no re-run came;
  • sets the attributes without re-running when GSAP has parsed none of them;
  • an older frame's parser refuses a restore that carries a re-run;
  • drops a re-run with an empty script, a field soft-reload does not take, an authored style over its limit, or no object, and keeps the restore;
  • sets the attributes in place when the re-run it carried was dropped and none is needed;
  • "a re-run that waits for the MotionPath plugin": a table of 17 orderings (ok, scrub,ok, ok,scrub, same,ok, same,fail, ok,same, fail,same, other,ok, other,fail, ok,other, attr,ok, ok,attr, edit,ok, ok,edit, play,ok, two,ok, patch,ok), checking the answer, which script ran for each timeline, the restored attribute, the edit and the playhead; and "starts a fresh plugin load for the next re-run after one failed".

Studio, real Chrome with the real runtime and the plugin request held, gsapSoftReloadWait.browser.test.ts, sealed (a sandboxed frame) and unsealed (reads HF_PARITY_MODE):

  • the same table, plus move,ok and ok,move (an inline transform on the animated layer), same,late,ok (the plugin held 5.5 s, past the editing port's 5 s) and drag,ok,drag (a drag preview frame on each side of the swap), through Studio's own applySoftReload and, sealed, its restore-attributes request;
  • "the first motion-path re-run after load finds the plugin loaded".

Against main for the edit rows, in real Chrome: an edit to a property the timeline does not animate (color) is kept in both. An inline transform written on the animated layer during the wait differs: main's new tween starts from it (x 180 at 2 s), this change starts it from the authored value, as a fresh load shows (x 30). Written after the swap, both keep it (x 300).

Studio, gsapUndoRestore.sealed.test.ts:

  • "carries the script re-run in the restore request when the file keeps a script";
  • "sends no re-run when the files have no script";
  • "leaves an edit sent while the restore waits, and the playhead it was sent at": only the restore (at the undo's playhead) and the edit go out; the late refusal reloads;
  • "sends nothing more after a reply a new preview load lost";
  • "reloads a timed-out re-run only when no newer run was sent for its timeline" (both cases).

Studio, useGsapScriptCommits.sealed.test.ts: "re-runs the saved script in place when the frame refuses a patch of a soft-reloadable edit".

Studio, sealedPreviewLedger.test.ts, every reply held and answered in any order: "re-runs a refused patch's recovery with the timing of a live retime saved after it" (the reviewer's retime sequence, through Studio's moveLiveTweens); "drops an older explicit refusal once a newer re-run of its timeline was sent"; "re-runs the newest saved script when a patch refusal held while a newer patch lands arrives"; "still recovers an older script run that times out after an attribute-only undo of its timeline"; "ignores a restore answered after the next load"; and two guards, "still recovers an older script run after an unrelated successful patch of its timeline" and "does not let a re-run sent while a patch's write was in flight cover the patch".

Studio, real Chromium, sealed, two files sharing one fixture (studio/tests/sealedOrderingFixture.ts; harness in studio/tests/sealedPreviewHarness.ts, sequence runner in studio/tests/sealedPreviewSequence.ts): sealedPreviewOrdering.browser.test.ts holds 30 fixed sequences (the round-9 and round-10 pinned seeds as literal steps); sealedPreviewOrderingGenerated.browser.test.ts holds generated sequences, seeds 1 to 40 by default, the same in every CI run, so a red seed there can be rerun by number. HF_ORDERING_SEEDS, HF_ORDERING_SEED_BASE and HF_ORDERING_SEED_LIST change them only for local runs such as the five-run bar. The split keeps each file well under the flake gate's 120 s per file under contention.

  • Generator steps (8 per sequence): a frame reload; a scrub of Studio's playhead to 1, 3 or 4 s (player store and frame together); the oldest pending request deadline passing (deadlines fire only at this step or at the end, so a reply after it arrives too late); an older live retime or retime re-run and a newer run, patch, label undo or data-start undo whose responses come back newest first, the older one's sync answered by the frame, sometimes with a load of the newer file between them; an answer to one pending reply or refusal, picked at random; or a save, each sent the way Studio sends it after writing the file: a script re-run, a tween patch, a retime of data-start through the soft re-run with timing, a live retime (data-start and a tween duration) through moveLiveTweens with Studio's timing-sync fallback, an undo of a restore-safe attribute (data-label), of an unsafe one (title, refused by the frame), of the script and the title together, or of the data-start of a clip no script animates. Each save reaches the frame (reply held), is refused (answered later with the frame's refusal), is rejected by the port before the frame applies anything (answered later with ok: false, code invalid-params), or is never answered (only its deadline settles it). Odd seeds play a file with two GSAP scripts.
  • After every reply settles, the preview (script, data-start, data-label, title, the tween at 2 s) equals a fresh load of the saved file, the preview's playhead is within a frame of Studio's, and a full reload happens only after a refusal or missed deadline that leaves nothing to recover in place (or in a two-script file, where a recovery may only reload). A new load is shown at Studio's playhead, as the real preview's reload shows it. Each save marks Studio's file revision, as Studio's write does.
  • Fixed: the reviewer's round-7 sequences (an undo of a script and a title the frame refuses, held past a newer script-only run; a refused patch, then a static undo) and a guard (a refused patch, then a refused retime re-run); the reviewer's round-8 sequences (a refused patch, a live retime whose refusal is pending and a static undo; a refused live retime, then a script-only run; a refused live retime at 2 s, a newer run, a scrub to 4 s; a retime the port rejects before applying, answered after a newer script-only run painted).
  • Fixed, the reviewer's round-12 sequences: the round-11 pair with the frame loading the newer saved file between the newer and the older sync (the harness's reload records the revision at its start and hands it over once the load shows, as Studio's does).
  • Fixed, the reviewer's round-11 sequences: an older live retime, and an older retime re-run, whose sync goes out after a newer undo of another clip's data-start and gets a successful frame reply; the clip keeps the undo's timing.
  • Fixed, the reviewer's round-10 sequence and its control, each checked for no reload: a held retime refusal, a newer retime applied, a script-only run applied, then the refusal; the same without the script-only run. And a live retime and a newer run whose responses come back newest first (the generator's reversed step: both saves marked in order, the newer's preview sync sent first), and generated seeds 52 and 148, which found that class.
  • Fixed, the reviewer's round-9 sequences: in a two-script file, a refused patch, then an applied undo of data-start, then the patch's refusal; an undo of a script and a title the frame refuses and a newer run, both answered after the undo's deadline.
  • Pinned, the round-9 generator's seeds that found each class with 961b71b's code: 312 and 320 (a write of saved state never answered, then covered by a script-only run), 2101, 3037 and 3657 (a two-script file's newer timing undo overwritten). The round-8 pinned seeds are kept as literal step lists, since the generator changed.
  • Pinned (as literal steps), the generated seeds that found each round-8 class with 441bbe5's code: 50 (a recovery dropping saved timing), 80 and 261 (a recovery rewinding a newer scrub), 312, 147 and 377 (a port rejection taken for a missing reply; 147 and 377 on an undo of a script and a title).

Studio, real Chromium, sealed, the frame's real replies held in transit (gsapSoftReloadWait.browser.test.ts, "late answers held in transit, sealed"): an older explicit refusal after a newer run painted; a patch refusal held across the swap while a newer patch lands; an older run timing out (held past the port's 5 s) after an attribute-only undo; a restore its old load never answered across a preview reload; and a guard, an older script refusal after an unrelated successful patch.

fails without the fix:

  • with the new load's floor taken out (previewLoadShows a no-op, as at 0b0e114), the reviewer's two round-12 sequences fail (the unrelated clip back at data-start 0 where the saved file has 1), and so does the ledger row that sends an older live retime to a new load showing a newer file; with 0b0e114's code, generated seeds 178, 210 and 316 fail too (a tween's x).
  • with Studio's sealed-preview files as at c12ab10 (round 10) and the round-11 harness, 10 of 428 ordering sequences fail: the reviewer's two round-11 sequences (the unrelated clip back at data-start 0 where the saved file has 1), and eight generated seeds found by themselves (52, 118, 231, 307 and 366 a clip's data-start, 54 and 178 a tween's x, 395 an older script). The two new ledger rows (sealedPreviewLedger.test.ts: an older live retime sent after a newer re-run, and after a newer undo of another clip) fail there too.
  • with Studio's sealed-preview files as at 2fedba8 (round 9: the ledger, the soft re-run, restore, live retime and channel, and the save paths that now carry a revision) and the round-10 harness, 11 of 424 ordering sequences fail: the reviewer's round-10 sequence (one reload), the reversed-response row (the older script left on screen), and nine generated seeds found by themselves (52, 83, 148, 149, 173, 231, 261, 266 and 346: an older script or a lost patch value). The round-10 control passes there.
  • with Studio's gsapSoftReload.ts, gsapUndoRestore.ts, useGsapScriptCommits.ts, gsapLiveRetime.ts, previewChannel.ts and sealedPreviewLedger.ts as at 961b71b (round 8) and the round-9 harness, 7 of 419 ordering sequences fail: both of the reviewer's round-9 sequences, and the five pinned round-9 seeds (312 and 320: a write of saved state never answered and then covered by a script-only run, data-start and title lost; 2101, 3037 and 3657: a two-script file's newer data-start undo overwritten). The round-8 rows, the reload guard and 400 generated seeds pass there. In those 400 seeds the generator found 312 and 320 by itself; the two-script class needs its shape (a refused patch or live retime, then an applied data-start undo before any reload), and a scan of odd seeds to 4000 for that shape gave 52 candidates, of which 2101, 3037 and 3657 fail.
  • with Studio's code as at 441bbe5 (round 7) and the round-8 harness, 400 generated seeds (base 0) find all three classes by themselves: seeds 50, 80, 147, 261, 312 and 377 fail and the other 394 pass; at 40 seeds the third class is missed (seed 312 is the first). All four of the reviewer's round-8 sequences fail there. The round-7 sequences pass there.
  • with core's softReload.ts and Studio's gsapSoftReload.ts, gsapUndoRestore.ts, useGsapScriptCommits.ts, gsapLiveRetime.ts, previewChannel.ts and sealedPreviewLedger.ts as at b8a3637 (round 6), 4 of the 43 ordering sequences fail: the title undo and seed 29 (title not on screen), the static undo (an unneeded full reload) and seed 28 (data-start lost, a refused retime covered by a script-only run); the guard sequence passes there too; and "re-runs a refused patch's recovery with the timing of a live retime saved after it" fails (the re-run carries no timing).
  • with core's softReload.ts and Studio's gsapSoftReload.ts, gsapUndoRestore.ts, useGsapScriptCommits.ts, gsapLiveRetime.ts and previewChannel.ts as at d9b8cae (round 5), the four core restore-attributes cases (now checking reran), four of the six sealedPreviewLedger.test.ts rows and four of the five held-answer Chromium rows fail; the three guard rows pass there too.
  • with gsapUndoRestore.ts as on main, "carries the script re-run in the restore request when the file keeps a script" fails.
  • with gsapUndoRestore.ts as at 4df4f85 (the re-run sent after the reply), "carries the script re-run in the restore request when the file keeps a script", "leaves an edit sent while the restore waits, and the playhead it was sent at" and "sends nothing more after a reply a new preview load lost" fail.
  • with the frame ignoring rerun, "re-runs the script in the same request when GSAP has parsed a restored element" fails.
  • with softReload.ts as at 23fa4fa, the four "drops a re-run with …" cases fail.
  • with core's softReload.ts, patchTween.ts, liveRetime.ts and init.ts and Studio's gsapSoftReload.ts, gsapUndoRestore.ts, gsapRuntimePatch.ts, useGsapScriptCommits.ts and sealedTweenPatch.ts as at a665227 (round 4), the core table fails ok, scrub,ok, play,ok and two,ok; the timed-out case with a newer run sent fails; the refused-patch re-run fails; and the Chrome table fails 15 of its 44 rows across both modes (among them play,ok, two,ok, patch,ok and same,late,ok).
  • with core's softReload.ts and restoreAttributes.ts and Studio's gsapSoftReload.ts as at 3948815 (the runtime rebuilt for the Chrome test), the core table fails same,ok, same,fail and other,ok, and the Chrome table fails 15 of its 34 rows across both modes (among them scrub,ok, same,fail, other,ok, other,fail, edit,ok and move,ok).

Run on Linux at 848d02c (0847d49 moves the runner's reversed step into its own function): the fixed file (30 sequences) 30/30, and the generated file five times with fresh seeds (seed bases 0, 1000, 2000, 3000, 4000; 100 each) 100/100 every run: 530 sequences, no problems. Four copies of the wait table and the fixed file run at once pass every time. Studio's wide run (9157 tests) passes, the shadow reload's tests included; the ledger rows pass three runs in a row. At 0847d49: Studio tsc no errors, both ordering files (70) pass, fallow audit no issues in 44 changed files. Round 10's two red checks are fixed: the sealed restore's send moved to sealedRestoreSend.ts (the 600-line cap), and two wait-table rows now settle before reading (the second waiting run, the paused frame). At c4fd71a (the same code before the split): Studio's wide run (9145 tests) and the touched Studio tests (339) pass. At 961b71b, Studio's wide run (9137 tests) passes. Earlier, at adaab5a (core unchanged since): core softReload, patchTween, liveRetime, restoreAttributes, editingAgent and editingPort tests (254) and Studio's touched tests (343, the wait and ordering tables included) pass three runs in a row; core's runtime tests (3512) and Studio's utils, hooks, components/editor, webmcp and player tests (7731) pass; core and Studio tsc no errors. Format and lint clean.

Proof

Sealed preview, three crop cases (a tweened layer, a gsap.set layer, a tweened layer placed by xPercent and turned 30°), cropped, then undone. Counted from the undo key, one case at a time:

case main: documents loaded, back in place this change
tween, root, 100% zoom 2, 441 ms 0, 54 ms
hold, root, 50% zoom 2, 1190 ms 0, 62 ms
tween, xPercent, r30, root, 50% zoom 2, 1291 ms 0, 65 ms

On main, the documents are the frames the reload navigates; with this change no frame navigates.

Bench

Edit-accuracy bench, every crop case (120 per run), at main and at this change:

preview undo off redo off drop off reload off
sealed, main 15 1 0 0
sealed, this change 0 0 0 0
unsealed, main 0 0 0 0
unsealed, this change 0 0 0 0

The 15 sealed undo misses on main are the root hold and tween layers: the bench measured them before the reload finished, so the layer still showed the crop (40 px, the cropped edge). Run alone with a 3 s settle, the same cases pass on main. This branch's base is before #8310, so its sealed runs still show #8310's turned crop frame misses (46 and 48, on turned layers only, in different cases from run to run); this change does not touch the crop frame.

Before

Sealed preview on main, a tweened layer cropped, then undone: the preview reloads (2 documents) and the layer is back after 441 ms.

before: the undo reloads the preview

After

The same undo at this change: no document loaded, and the layer is back after 54 ms.

after: the undo shows in place

@terencecho terencecho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two preview-ordering issues remain at 4df4f85c.

  • P2 · An undo can overwrite an edit made while it waits. gsapUndoRestore.ts:413–435 advances the counter only for history restores. A normal GSAP edit can update the same frame through useGsapScriptCommits.ts:229–236 without advancing it. In a delayed-reply test, Studio sent the new script, then the older undo's refusal triggered a second soft reload with the old script and styles. The saved file has the newer edit, but the preview shows the older one. Invalidate the fallback on intervening preview writes as well as on later history restores. Preserve the current playhead when issuing a delayed retry, since the captured time can also predate a scrub.
  • P2 · A lost reply can retry into a different preview load. gsapUndoRestore.ts:451–454 treats null like an explicit refusal. previewChannel.ts:26–38,87–96 also returns null when the old frame's editing client is disposed, and the follow-up request can acquire a new client for the same iframe element. The element-keyed counter still matches. Keep the retry tied to the original editing client and require an explicit refusal. A timeout on the current preview can use the existing full reload.

The PR body names the regression required by the review rule. The build and 165 targeted tests passed, including 11 in Chrome. The named regression failed with the implementation reverted. Two additional request-ordering probes confirmed the stale script and the retry after a missing reply.

— tai (automated review)

@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 271 (base branch 271), smooth 69 of those

The gate passes.
Smoothness is reported in the artifact, not gated. A case fails only if it fails 2 of 3 runs.

Quarantined, measured but not gated (0)

Unstable (1)

  • seqrotatenudge-none-pct-r0-root-z100: tracking 0.03, pressJump 0, drop 0, reload 3.03, render 0.04, renderKey -, undo false, teleport true / tracking 0.03, pressJump 0, drop 0, reload 0, render 0.08, renderKey -, undo true, teleport true / tracking 0.03, pressJump 0, drop 0, reload 0, render 0.08, renderKey -, undo true, teleport true

@miguel-heygen

Copy link
Copy Markdown
Collaborator Author

Both points are fixed by removing the second request, at 23fa4fa.

The re-run no longer goes out after the reply. Studio puts it in the restore-attributes request itself, as an optional rerun (script, standalone sets, authored styles, timing). The frame decides, since only it knows which elements GSAP has parsed. When a restored element is one of them, it calls the existing softReload with that rerun, the request's time and its scopes, through the same planRestore (so #8264's rule applies). Otherwise it sets the attributes as before. A refusal or no reply reloads the preview; nothing else is sent.

  • An undo can overwrite an edit made while it waits. Nothing follows the reply any more, so a GSAP edit, a later undo or a scrub sent meanwhile is never replayed over. The re-run runs at the time captured with the undo, in its own request's turn, before any later request. The counter (sealedRestoresSent) is deleted. Test: "leaves an edit sent while the restore waits, and the playhead it was sent at". It fails at 4df4f85, where the late refusal sent a soft-reload at time 2 after the edit's at 3.
  • A lost reply can retry into a different preview load. A null reply (a disposed client, a timeout) only reloads. No request is made on any client after it. Test: "sends nothing more after a reply a new preview load lost". It fails at 4df4f85.

Also:

  • The rerun is attached only when the file keeps a GSAP script.
  • The parser accepts exactly its four fields.
  • A frame built before this refuses the unknown field, so Studio reloads as today (tested).
  • The editing agent answers only a Studio-marked page connected from its parent (editingAgent.ts:285, :289), so renders never reach it.

Checked on Linux at 23fa4fa:

  • The touched core (213) and Studio (125) tests pass three runs in a row.
  • Core runtime (3468) and Studio's wide run (7606) pass.
  • Core and Studio tsc, Studio vite build and fallow audit are clean.
  • The engine and producer unit failures are identical on main at this branch's base.

Remeasured at this head, sealed preview, one undo of a crop at a time: no preview document loads, and the layer is back in place after 54 to 65 ms. On main it reloads (2 documents) and takes 441 to 1291 ms. The crop bench is in the body: sealed undo 15 and redo 1 off on main, 0 and 0 here; unsealed 0 and 0 on both.

@terencecho terencecho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The restore now sends one request, and the delayed-reply and navigation checks passed in sealed Chrome. Two P2s remain.

  • P2 · packages/core/src/runtime/editing/softReload.ts:511 — When the re-run waits for MotionPath, completion still seeks to the original undo time. I scrubbed from 1.5 s to 4 s while the plugin was pending. Completing the load moved the playhead back to 1.5 s. Preserve a newer seek during the wait, or use the reload fallback for a restore that needs to wait for the plugin.
  • P2 · packages/core/src/runtime/editing/softReload.ts:634 — An optional re-run can block a static restore that never needs it. In sealed Chrome, a static style undo stayed in place until I added an unrelated inline SVG style above the 16 KiB re-run field limit. The restore then requested a full reload. The base sender kept the same fixture in place. Preserve the valid static restore and use the reload fallback only if the frame needs a re-run it cannot accept.

The build, 152 targeted unit tests, and 11 existing Chrome tests passed. The named red-first tests failed with the old behavior. The full suites and edit-accuracy benchmark were outside this pass.

— tai (automated review)

@miguel-heygen

Copy link
Copy Markdown
Collaborator Author

Both fixed at 5822316, red-first.

  • A pending MotionPath load can rewind a newer scrub. I fixed it where every soft reload finishes: softReloadFrame, which edits use too. The frame notes its player's time when the re-run starts. When the re-run had to wait for the plugin and the player's time moved meanwhile, it finishes at the newer time instead of the one it was sent with. A re-run that does not wait is unchanged. Test: "keeps a seek made while the re-run waits for the MotionPath plugin". It fails at 23fa4fa, where the finish seeks back to 1.5 after a scrub to 4.
  • A large unrelated inline style can force a full reload on a static undo. The frame now drops a rerun it cannot take: an over-limit field, an unknown field, an empty script, or a non-object. It keeps the restore. A static restore then applies in place. A restore that needs the re-run gets no re-run and is refused, so Studio reloads, as before. Tests: "drops a re-run with an authored style over its limit and keeps the restore" (and the other three shapes), plus "sets the attributes in place when the re-run it carried was dropped and none is needed". All five fail at 23fa4fa, where the request was refused.

The player time the fix compares is the Studio preview's own clock time (init.ts:5374). The editing agent runs only in that preview, and killing the composition's timelines does not move that clock.

Checked on Linux at 5822316:

  • The touched core (216) and Studio (125) tests pass three runs in a row.
  • Core runtime (3471) and Studio's wide run (7606) pass.
  • Core and Studio tsc, Studio vite build and fallow audit are clean.
  • The engine and producer unit failures on that machine are identical on main; CI runs both green.

The probe and bench numbers in the body stand: the change only affects a re-run that waits for the plugin, and a re-run the frame drops.

@terencecho terencecho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The oversized unrelated style now leaves the plain restore available, and a single scrub to a different position survives a pending MotionPath load. Two overlaps still fail in sealed Chromium.

  1. P2 — Scrubbing away and back can rewind playback (packages/core/src/runtime/editing/softReload.ts:466). The comparison uses the initial and final playhead values. If the restore carries Studio's 2s position, the frame starts at 4s, and the user scrubs to 5s and back to 4s before the plugin loads, the comparison sees equal values and finalizes at 2s. Track seek ordering across the wait so the latest scrub wins even when the time returns to its initial value.
  2. P2 — A pending undo can replace a newer animation edit (packages/core/src/runtime/editing/softReload.ts:521). The plugin callback still runs the old script after a newer soft reload has succeeded. In sealed Chromium, the newer edit installed a tween ending at 120px. Releasing the pending plugin load restored the old 60px tween. Check whether playback has received a newer reload for the same timeline before executing the deferred script.

— tai (automated review)

@miguel-heygen

Copy link
Copy Markdown
Collaborator Author

Both fixed at 3948815, red-first, in softReloadFrame, which edits use too (gsapSoftReload.ts:253). The wait for the plugin stays; it now handles both races itself.

  • A scrub away and back during the wait rewound the playhead. Comparing the player's time could not see a scrub that came back to where it started. The runtime player now counts every seek (countPlayerSeek, called from its seek). A re-run that waited for the plugin finishes at the player's latest time when any seek happened during the wait, and at the time it was sent with otherwise. A re-run that does not wait is unchanged.
  • An older delayed re-run replaced a newer animation edit. Each soft reload is numbered when it starts. A re-run that waited and finds a newer soft reload started meanwhile does not run its script; the newer one's timeline stays. The waiting re-run also leaves the composition's script in place until it runs. Before, it removed it up front, so in real Chrome the newer edit found no script to replace and reloaded the whole preview.

A sealed preview now also loads the MotionPath plugin ahead of time, as a same-origin preview does (NLEContext.tsx:164). The frame starts the load when Studio connects its editing port, from the same address owner (previewMotionPathUrl), never from anything in the film. So the first motion-path re-run after a load runs at once in both modes, and the wait is only a fallback.

Tests, in real Chrome with the real runtime, a sandboxed preview frame and the plugin request held (gsapSoftReloadWait.browser.test.ts):

  • "ends a sealed re-run that waited for the plugin where the player was scrubbed away and back to";
  • "keeps a newer sealed edit made while an older re-run waited for the plugin";
  • "the first motion-path re-run after load finds the plugin loaded", sealed and unsealed (reads HF_PARITY_MODE).

Plus core unit cases for each race in softReload.test.ts ("a re-run that waits for the MotionPath plugin").

With core as at 5822316, all three Chrome tests fail: the scrubbed re-run ends at 2 s instead of 4 s, the newer edit falls back to a full reload, and the sealed preview never loads the plugin. The three core cases fail there too.

Checked on Linux at 3948815:

  • The touched core (218) and Studio (129) tests pass three runs in a row.
  • Core runtime (3473) and Studio's wide run (7610) pass.
  • Core and Studio tsc, Studio vite build and fallow audit are clean.

@terencecho terencecho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two P2s remain in packages/core/src/runtime/editing/softReload.ts.

  • Line 529 — A waiting re-run can lose an independent timeline. The supersession counter is frame-wide, but a re-run replaces only its own timeline keys. In sealed Chrome, I held the plugin load for main, applied an edit to other, then released the plugin. Both requests reported success and only other remained in the registry. A newer reload should supersede the waiting work only for the timelines it replaces.
  • Line 546 — A superseded request can still force a full reload. The plugin error callback skips the supersession check. In sealed Chrome, a newer edit to the same timeline completed in place, then failing the older plugin request still triggered Studio’s reload fallback. Apply the supersession decision on failure as well as success.

The prior scrub and same-timeline overwrite cases now pass. The workspace build and 159 targeted tests passed offline, including the new MotionPath cases. The six named prior-head regressions failed as expected when run against the previous implementation. Both findings above reproduced in sealed Chrome.

— tai (automated review)

@miguel-heygen

Copy link
Copy Markdown
Collaborator Author

Both fixed at cdabe44, by making the soft-reload wait one state machine in softReloadFrame instead of patching the two cases.

  • A newer edit to a different timeline left the waiting timeline missing. Each timeline a run replaces is now numbered when the run starts, and a waiting run is decided by its own timelines only. An edit to other during main's wait leaves main's run current, so it swaps when the plugin arrives. And a waiting run no longer kills anything up front: the kill, the reset of the tweened styles, the removal of its stale script and the script run all happen together at the swap. A run a newer one superseded therefore changes nothing, and the timelines it would have replaced keep running.
  • An older plugin failure forced a reload after a newer edit succeeded. The failure is decided the same way as the load: a run no longer current answers superseded, which Studio treats as done, and only a current run answers cannot-soft-reload.

What a run writes from the file (its restore plan and timing) still lands when it starts, in arrival order, so a later attribute restore or edit is never written over by an older waiting run. While a run waits, the old timeline keeps playing over those restored attributes, as it did before this change.

The real-Chrome tests also showed that a run joining a plugin load already in flight (the connect preload, or Studio's same-origin preload) polled for it every 50 ms. Core now has one loader: every waiting run queues on the single request in flight, and its load or error settles them all at once, in arrival order. Studio's same-origin preload calls it instead of keeping its own copy. A failed load is not remembered; the next run requests it again.

Tests: a table of every ordering of plugin ok or failing with a scrub, a newer run on the same timeline, a newer run on another timeline, an attribute restore and an edit, in core (softReload.test.ts) and in real Chrome, sealed and unsealed (gsapSoftReloadWait.browser.test.ts). Both of your cases are rows (other,ok, same,fail). With round 3's code, three core rows and 15 of the 34 Chrome rows fail.

Against main, an edit to a property the timeline does not animate is kept in both. An inline transform written on the animated layer during the wait differs: main's new tween starts from it, this change starts from the authored value, as a fresh load shows.

preloadMotionPath and the loader's queue are reached only from the editing agent's connect (editingAgent.ts:294, behind :285 and :289, so never in a render) and from Studio.

Checked on Linux at cdabe44:

  • The touched core (230) and Studio (150) tests pass three runs in a row.
  • Core runtime (3485) and Studio's wide run (7640) pass.
  • Core and Studio tsc and fallow audit are clean.

@terencecho terencecho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes requested at a665227e. The prior disjoint-timeline cancellation and prompt stale-plugin-error cases pass. Four failures remain in Chrome.

  • P2 · packages/core/src/runtime/editing/softReload.ts:517–542. An older waiting script can overwrite a newer value-only edit. In sealed Chrome, the editing port's patch-tweens request returned patched: true and the element moved to x=300. Releasing the older MotionPath wait replaced that tween and moved it back to x=60. A successful patch skips a fresh rerun in Studio, so no generation changes before the older swap. Account for the in-place tween patch in the same ordering as a rerun.
  • P2 · packages/studio/src/utils/gsapSoftReload.ts:213–221. An old sealed request can still reload the preview after a newer run has already landed. Hold the MotionPath response, request a run on one timeline, and apply a newer run on that same timeline. A prompt plugin failure correctly leaves the preview alone. Holding the response past the editing-port deadline calls the old request's reload callback while the newer timeline is visible. The host treats the timed-out request as a fresh refusal before the frame can report supersession. Apply the ownership check to timeout and cancellation outcomes as well as normal replies.
  • P2 · packages/core/src/runtime/editing/softReload.ts:480–488. Two different timelines waiting for the same plugin can land at the older run's requested time. I queued waits at 2 s and 3 s, with no user seek after either request. Both scripts ran, but both preview modes settled at 2 s. The first swap's own seek increments the same counter used to detect a newer user seek, so the second swap treats 2 s as the newer time. Separate the swap's bookkeeping from user playback position changes.
  • P2 · packages/core/src/runtime/editing/softReload.ts:487–488. Playback can continue during a wait without changing the seek count. In both preview modes I queued a run at 1 s, started playback, and let it advance past 1.5 s before releasing MotionPath. The swap resumed playback near 1 s. Use the live playhead when playback advanced while a run was pending.

I ran all 34 sealed and unsealed Chrome cases alongside 230 focused core tests and 133 targeted Studio tests. The previous implementation failed the same-timeline stale failure and different-timeline wait controls.

— tai (automated review)

@terencecho terencecho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes requested at c12ab108.

P2 · packages/studio/src/utils/gsapLiveRetime.ts:195 and packages/studio/src/utils/gsapSoftReload.ts:233. A successful older timing sync can overwrite an unrelated clip's newer saved timing. The ledger versions the snapshots it uses for recovery, but the initial frame request still sends every clip's timing from the older snapshot. I delivered a newer undo at the preview-sync boundary first, then delivered the older retime and let the frame apply it. The older sync left the unrelated clip at data-start="0" while a fresh load of the saved file showed "1". Both the live-retime and rerun paths reproduced it in sealed Chromium. Their in-order controls passed. A temporary revision check that reloaded the saved file before sending the older timing passed both reversed cases. Preserve the newer state before applying an older sync, and keep a test where that older request gets a successful frame reply.

The earlier timing-coverage case now completes with zero reloads. It produces one reload with the previous ledger. The pinned reversed-response refusal case also passes and is red with the previous ledger. 175 Chromium cases and 285 scoped Studio tests passed. I checked this ordering at the production preview-sync boundary, with the save completion order controlled by the fixture. All required hosted checks passed. The body has named fails-without evidence and could also name this round's two new cases.

— tai (automated review)

@terencecho terencecho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 · A fresh preview load can still accept older saved timing (packages/studio/src/utils/sealedPreviewLedger.ts:72, :125).

The new send gate fixes both reversed-save cases on the same load. The gate starts at version zero on a new load, though, even when that frame already loaded a newer saved file. In sealed Chromium I held the older retime completion, applied the newer undo of another clip's data-start, then loaded a frame from the newer saved bytes before delivering the older completion. Both the live-retime and the soft-reload paths sent the old timing to the loaded frame, changing the untouched clip's data-start from 1 back to 0. The same-load controls passed. I reproduced it both on a new load of the same iframe and when the sync selected the replacement iframe.

Give admission a version floor for the file state the frame loaded, or keep delayed sync work tied to its original load and converge from the saved file when the load changed. Add the reload-between-completions case for both timing paths.

Validation included 177 Chromium cases and 294 scoped Studio tests. Disabling the admission check turns both same-load reversed timing cases red. The additional reload cases fail on this head.

— tai (automated review)

@miguel-heygen

Copy link
Copy Markdown
Collaborator Author

Fixed at 0847d49.

Your finding. A new preview load now starts its send floor at the file revision Studio's shadow reload recorded when that load began, and checked before showing it. The reload hands that revision to the ledger as it promotes the load, so the one record of which file a load shows also sets the floor. Studio's preview reloads all go through it (useTimelinePlayer.ts:485), so this covers both the same iframe and a replacement one. A write older than the floor isn't sent to the new load and recovers by a reload. Your held completion therefore can't put the older file's clip timing on the newer load.

One consequence: a save whose request went out before a reload began but finished after it is below that floor too. Its sync reloads once more. It is never lost.

Tests. Your two cases are fixed rows: the round-11 pair with the frame loading the newer saved file between the newer and the older sync, for the live retime and the retime re-run. The harness's reload records the revision when it starts and hands it over once the load shows, as Studio's does. The generator's reversed step sometimes loads the newer file between the two syncs. A ledger row sends an older live retime to a new load that shows a newer file: nothing is posted, and the preview reloads.

Red without the fix. With the floor taken out (previewLoadShows a no-op, as at 0b0e114), both of your cases fail with the clip at data-start 0 where the saved file has 1, and the ledger row fails. With 0b0e114's code, generated seeds 178, 210 and 316 fail too.

Checked on Linux:

  • The fixed file (30 sequences) passes, and the generated file run five times with fresh seeds (seed bases 0 to 4000, 100 each) passes every time: 530 sequences, no problems.
  • Four copies of the wait table and the fixed file run at once pass every time.
  • Studio's wide run (9157 tests) passes, the shadow reload's tests included. Studio tsc is clean, and fallow audit finds no issues in the 44 changed files.

@terencecho terencecho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The shadow promotion now seeds the send floor from the revision it recorded at load time. A stale live retime or timing rerun is refused on that replacement load and recovers by reloading the saved file. The existing recovery check still requires timing coverage for every affected timeline.

124 scoped Studio tests and 179 Chromium cases passed, including 100 generated sequences. Both named replacement-load cases failed when revision seeding was disabled. I also checked the production promotion hook with a write during loading. GitHub's required checks are clear. The separate Flake gate was still running when I checked.

— tai (automated review)

@terencecho terencecho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The merge tree matches a clean merge of the reviewed head and main, and the PR patch ID is identical. All required checks passed. The fresh CodeQL analysis also passed. Its warning refers to alert 1243, which is already open on main at the unchanged compiler line.

I verified the merge and hosted checks for this head. No local tests were rerun for the merge-only update. Some optional checks were still running.

— tai (automated review)

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 21, 2026
Merged via the queue into main with commit c3a6739 Nov 22, 2026
104 checks passed
@miguel-heygen
miguel-heygen deleted the fix/sealed-undo-gsap-in-place branch November 22, 2026 00:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants